package club.babyf.nativeai.demo.algorithm;

/**
 * _19_LongestNonRepeatingSubSeq.
 *
 * @author zhanglei.
 * @date 2025/7/20 18:43.
 * @description 最长不重复子序列.
 */
public class _19_LongestNonRepeatingSubSeq {

    public int longestNonRepeatingSubSeq(String s) {
        int[] charIndex = new int[128];
        int left = 0;
        int maxLength = 0;

        for (int right = 0; right < s.length(); right++) {
            char currentChar = s.charAt(right);
            left = Math.max(left, charIndex[currentChar]);
            maxLength = Math.max(maxLength, right - left + 1);
            charIndex[currentChar] = right + 1;
        }

        return maxLength;
    }

    public static void main(String[] args) {
        _19_LongestNonRepeatingSubSeq longestNonRepeatingSubSeq = new _19_LongestNonRepeatingSubSeq();
        int i = longestNonRepeatingSubSeq.longestNonRepeatingSubSeq("abcabcaba");
        System.out.println(i);
    }

}
